<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {

    public function index(){
        $admin = session('admin');
        if(empty($admin)){redirect('Home/Index/loginView');}
        $model=M('menu');
        $menu=$model->field('menu.menu_id,menu.menu_name,menu.menu_href,menu.menu_parent,menu.`class`')
            ->join('interaction ON menu.menu_id = interaction.inter_mid','left')
            ->where('(interaction.inter_pid='.$admin['user_role']. ') AND (menu.switch=1)')->select();//print_r($menu);die;
        $menu_parent=[];
        $menu_child=[];
        foreach ($menu as $k => $v){
            if(empty($v['menu_parent'])){
                $menu_parent[]=$v;
            }else{
                $menu_child[]=$v;
            }
        }
        foreach ($menu_parent as $k => $v){
            $menu_parent[$k]['child']=[];
            foreach ($menu_child as $ke => $va){
                if($v['menu_id']==$va['menu_parent']){
                    $menu_parent[$k]['child'][]=$va;
                }
            }
        }
        //print_r($menu_parent);die;
        $logo=M('logo')->field('id,logo,ico,crm_logo,web_name,web_name_en')->find();
        $this->assign('menu',$menu_parent);
        $this->assign('logo',$logo);
        $this->assign('admin',$admin);
        $this->display();
    }

    public function common_css(){
        $logo=M('logo')->field('id,logo,ico,crm_logo')->find();
        $this->assign('logo',$logo);
        $this->display();
    }

    public function loginView(){//登录页面
        $this->display();
    }

    public function loginOut(){
        session('admin',null);
        $this->redirect('Home/Index/loginView','正在退出......');
    }

    public function index_frame(){//浮动窗口主页
        $model=M('user');
        $y = date("Y");
        $m = date("m");
        $d = date("d");
        $from = mktime(0, 0, 0, $m, $d, $y)+1;
        $to = mktime(0, 0, 0, $m, $d, $y)+(24 * 60 * 60);
        //echo date('Y-m-d H:i:s',$from).'******'.date('Y-m-d H:i:s',$to);die;
        $count['user']=$model->where(['user_role'=>1])->count();//MT4用户数
        $count['agent']=$model->where('(user_role=1) and (position>1)')->count();//经纪人用户数
        $count['gold']=M('into_gold')->where('(status=2) and (into_time between '.$from.' and '.$to.')')->sum('final_money');;//今日入金
        $count['rebate']=M('rebate_log')->where('time between '.$from.' and '.$to)->sum('money');//今日佣金发放

        $position=M('position')->field('id,user_position')->where('id>1')->select();//职位数据
        $user_group=$model->field('position,count(1)')->where('(user_role=1) and (position>1)')->group('position')->select();
        $userGroup=[];
        foreach ($user_group as $k => $v){
            $userGroup[$v['position']]=$v['count(1)'];
        }
        foreach ($position as $k => $v){
            $position[$k]['count_member']=$userGroup[$v['id']] ? $userGroup[$v['id']] : 0;
        }
        $thing['examine']=$model->where(['status'=>2])->count();//待审核用户数
        $thing['gold']=M('gold')->where(['status'=>1])->count();//提款待处理
        $thing['position_apply']=M('position_apply')->where(['state'=>1])->count();//职位申请待处理
        $thing['work_order']=M('work_order')->where(['state'=>1])->count();//工单待处理
        $thing['lever_apply']=M('lever_apply')->where(['state'=>1])->count();//杠杆申请待处理

        $news=M('article')->field('id,title,add_time,type')->order('id desc')->limit(10)->select();
        $this->assign('count',$count);
        $this->assign('position',$position);
        $this->assign('thing',$thing);
        $this->assign('news',$news);
        $this->display();
    }

    public function leavingMessageList(){//留言列表
        $admin = session('admin');
        if(empty($admin)){echo "身份信息过期请重新登录";exit;}
        $model = M('book');
        $count = $model->count();
        $Page = new \Think\Page($count,15);
        $show = $Page->show();
        $list = $model->field('book_id,book_name,book_phone,book_email,book_content,add_time,status')
            ->order('book_id desc')->limit($Page->firstRow.','.$Page->listRows)->select();

        $this->assign('list',$list);
        $this->assign('page',$show);
        $this->display();
    }
    //新闻公告列表
    public function leavingMessingDetail(){//留言详情
        $id = I('id');
        $msg=M('book')->where(['book_id'=>$id])->find();
        $this->assign('msg',$msg);
        $this->display();
    }

    public function leavingMessingSave(){//留言详情状态保存
        $id=I('post.id') ? I('post.id') : die(json_encode(array('status'=>0,'msg'=>'非法操作')));
        $data['status']=I('post.status') ? I('post.status') : 0;
        $data['remark']=I('post.remark') ? I('post.remark') : '';
        $res=M('book')->where(['book_id'=>$id])->save($data);
        if($res){
            $this->ajaxReturn(array('status'=>1,'msg'=>'操作成功'));
        }else{
            $this->ajaxReturn(array('status'=>0,'msg'=>'操作失败'));
        }
    }

    public function articleList(){//新闻/公告列表
        $admin =session('admin');
        if(empty($admin)){echo "身份信息过期请重新登录";exit;}

        $type = I('type')?I('type'):0;
        $title = I('title')?I('title'):'';
        if(!empty($type)){
            $where['type'] = $type;
        }
        if(!empty($title)){
            $where['title'] = array('like',$title.'%');
        }
        if(empty($where)){
            $count =  M('article')->count();
            $Page = new \Think\Page($count,10);
            $show = $Page->show();
            $data = M('article')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        }else{
            $count =  M('article')->where($where)->count();
            $Page = new \Think\Page($count,10);
            $show = $Page->show();
            $data = M('article')->where($where)->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        }
        $this->assign('data',$data);
        $this->assign('page',$show);
        $this->display();
    }
    //公告修改
    public function article_save(){
        $id = I('id')?I('id'):die();
        $data = M('article')->where(['id'=>$id])->find();
        if(!empty($data)){

            $this->assign('data',$data);
            $this->display();
        }
    }

    public function article_delete(){
        $id=I('post.id') ? I('post.id') : die(json_encode(array('status'=>0,'msg'=>'非法操作')));
        $res=M('article')->where(['id'=>$id])->delete();
        if($res){
            $this->ajaxReturn(['status' =>1, 'msg' =>'删除成功']);
        }else{
            $this->ajaxReturn(['status' => 0, 'msg' => '删除失败']);
        }
    }
    //公告修改信息更新
    public function article_saveData(){
        $id = I('get.id')?I('get.id'):die('没有信息');
        $data['title'] = I('title')?I('title'):die("标题不可为空");
        $data['type'] = I('type')?I('type'):1;
        $data['content'] = I('content')?I('content'):die("内容不可为空");
        $data['add_time'] = time();
        if(!empty($_FILES['img']['size'])) {  //图片不为空时
            $upload = new \Think\Upload();// 实例化上传类
            $upload->autoSub = false;
            $upload->maxSize = 20145728;// 设置附件上传大小
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg', 'JPG');    // 设置附件上传类型
            $upload->rootPath = './Uploads/';                     // 设置附件上传根目录
            $upload->savePath = 'article/';                                  // 设置附件上传（子）目录
            $info = $upload->upload();
            if (!$info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            } else {// 上传成功 获取上传文件信息
                $data['img'] = 'Uploads/' . $info['img']['savepath'] . $info['img']['savename'];
            }
            $article_save = M('article')->where(['id'=>$id])->save($data);
        }else{
            $article_save = M('article')->where(['id'=>$id])->save($data);
        }
        if($article_save){
            echo "修改成功";
        }else{
            echo  "修改失败";
        }
    }
    //公告添加
    public function article_addData(){
        $data['title'] = I('title')?I('title'):die("标题不可为空");
        $data['type'] = I('type')?I('type'):1;
        $data['content'] = I('content')?I('content'):die("内容不可为空");
        $data['add_time'] = time();
        if(!empty($_FILES['img']['size'])) {
            $upload = new \Think\Upload();// 实例化上传类
            $upload->autoSub = false;
            $upload->maxSize = 20145728;// 设置附件上传大小
            $upload->exts = array('jpg', 'gif', 'png', 'jpeg', 'JPG');    // 设置附件上传类型
            $upload->rootPath = './Uploads/';                     // 设置附件上传根目录
            $upload->savePath = 'article/';                                  // 设置附件上传（子）目录
            $info = $upload->upload();
            if (!$info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            } else {// 上传成功 获取上传文件信息
                $data['img'] = 'Uploads/' . $info['img']['savepath'] . $info['img']['savename'];
            }

            $article_add = M('article')->add($data);
            if($article_add){
                echo "提交成功";//<script language="JavaScript">alert("提交成功");location.href="article_add.html"</script>';
            }else{
                echo  "提交失败";//'<script language="JavaScript">alert("提交失败");location.href="article_add.html";</script>';
            }

        }else{
            echo "图片不能为空";
        }
    }

    public function videoList(){//视频列表
        $admin = session('admin');
        if(empty($admin)){echo "身份信息过期请重新登录";exit;}
        $model = M('video');
        $count = $model->count();
        $Page = new \Think\Page($count,20);
        $show = $Page->show();
        $list = $model->field('id,title,img,video,time')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);
        $this->assign('page',$show);
        $this->display();
    }

    public function addVideoView(){//添加视屏页面
        $admin =session('admin');
        if(empty($admin)){echo "身份信息过期请重新登录";exit;}
        $this->display();
    }

    public function addVideo(){//添加视屏
        $admin = session('admin');
        if(empty($admin)){echo "身份信息过期请重新登录";exit;}
        $data['title']=I('post.title') ? I('post.title') : $this->error('请设置标题');
        $data['content']=I('post.content') ? I('post.content') : $this->error('请设置内容');
        if(empty($_FILES['img'])||empty($_FILES['video'])){
            //$this->ajaxReturn(array('status'=>0,'msg'=>'请上传文件资源'));
            $this->error('请上传文件资源');
        }
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg','mov','avi','rmvb','mp4','wmv');// 设置附件上传类型
        $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
        $upload->savePath  =     'news/'; // 设置附件上传（子）目录
        $info   =   $upload->upload();// 上传文件
        if(!$info) {// 上传错误提示错误信息
            //$this->ajaxReturn(array('status'=>0,'msg'=>$upload->getError()));
            $this->error($upload->getError());
        }else{// 上传成功
            $data['img']='Uploads/'.$info['img']['savepath'].$info['img']['savename'];
            $data['video']='Uploads/'.$info['video']['savepath'].$info['video']['savename'];
        }
        $data['time']=time();
        $res=M('video')->add($data);
        if($res){
            //$this->ajaxReturn(array('status'=>1,'msg'=>'操作成功'));
            $this->success('操作成功');
        }else{
            //$this->ajaxReturn(array('status'=>0,'msg'=>'操作失败'));
            $this->error('操作失败');
        }
    }

    public function videoDetail(){//视屏详情
        $admin =session('admin');
        if(empty($admin)){echo "身份信息过期请重新登录";exit;}
        $id=I('id');
        $msg=M('video')->where(['id'=>$id])->find();
        $this->assign('msg',$msg);
        $this->display();
    }

    public function uploadFile(){//上传文件
        $admin =session('admin');
        if(empty($admin)){echo "身份信息过期请重新登录";exit;}
        if(empty($_FILES)){
            $this->ajaxReturn(array('status'=>0,'msg'=>'请上传文件资源'));
        }
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg','mov','avi','rmvb','mp4','wmv');// 设置附件上传类型
        $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
        $upload->savePath  =     'news/'; // 设置附件上传（子）目录
        $info   =   $upload->upload();// 上传文件
        if(!$info) {// 上传错误提示错误信息
            $this->ajaxReturn(array('status'=>0,'msg'=>$upload->getError()));
        }else{// 上传成功
            $src='Uploads/'.$info['news']['savepath'].$info['news']['savename'];
            $this->ajaxReturn(array('status'=>1,'msg'=>$src));
        }
    }

    public function updateVideo(){//修改视屏信息
        $admin = session('admin');
        if(empty($admin)){echo "身份信息过期请重新登录";exit;}
        $id=I('post.id') ? I('post.id') : die(json_encode(array('status'=>0,'msg'=>'非法操作')));
        $data['title']=I('post.title') ? I('post.title') : die(json_encode(array('status'=>0,'msg'=>'请设置标题')));
        $data['content']=I('post.content') ? I('post.content') : die(json_encode(array('status'=>0,'msg'=>'请设置内容')));
        $data['img']=I('post.img') ? I('post.img') : die(json_encode(array('status'=>0,'msg'=>'请上先传图片')));
        $data['video']=I('post.video') ? I('post.video') : die(json_encode(array('status'=>0,'msg'=>'请上先传视频资源')));
        $res=M('video')->where(['id'=>$id])->save($data);
        if($res){
            $this->ajaxReturn(array('status'=>1,'msg'=>'操作成功'));
        }else{
            $this->ajaxReturn(array('status'=>0,'msg'=>'操作失败'));
        }
    }

    public function deleteVideo(){//删除视屏
        $admin = session('admin');
        if(empty($admin)){echo "身份信息过期请重新登录";exit;}
        $id=I('post.id') ? I('post.id') : die(json_encode(array('status'=>0,'msg'=>'非法操作')));
        $res=M('video')->where(['id'=>$id])->delete();
        if($res){
            $this->ajaxReturn(array('status'=>1,'msg'=>'操作成功'));
        }else{
            $this->ajaxReturn(array('status'=>0,'msg'=>'操作失败'));
        }
    }

    public function about(){//关于我们
        $admin = session('admin');
        if(empty($admin)){echo "身份信息过期请重新登录";exit;}
        $msg=M('about')->where(['id'=>1])->find();
        $this->assign('msg',$msg);
        $this->display();
    }

    public function about_save(){
        $data['content']=I('post.content') ? I('post.content') : die(json_encode(array('status'=>0,'msg'=>'请输入内容')));
        $has=M('about')->where(['id'=>1])->find();
        if(empty($has)){
            $data['id']=1;
            $data['time']=time();
            $res=M('about')->add($data);
        }else{
            $res=M('about')->where(['id'=>1])->save($data);
        }
        if($res){
            $this->ajaxReturn(array('status'=>1,'msg'=>'操作成功'));
        }else{
            $this->ajaxReturn(array('status'=>0,'msg'=>'操作失败'));
        }
    }

    public function logList(){//日志列表
        $admin = session('admin');
        if(empty($admin)){echo "身份信息过期请重新登录";exit;}

        $this->display();
    }
    //轮播列表管理
    public function roll_manage()
    {
        $data = I('post.');
        $map = '';
        if($data['key']){
            $map['name'] = array('like',"%".$data['key']."%");
        }
        $count = M('rolls')->where($map)->count();
        $Page = new \Think\Page($count,10);
        $Page->setConfig('header', '<li class="rows">共<b>%TOTAL_ROW%</b>条记录&nbsp;第<b>%NOW_PAGE%</b>页/共<b>%TOTAL_PAGE%</b>页</li>');
        $Page->setConfig('prev', '上一页');
        $Page->setConfig('next', '下一页');
        $Page->setConfig('last', '末页');
        $Page->setConfig('first', '首页');
        $Page->setConfig('theme', '%FIRST%%UP_PAGE%%LINK_PAGE%%DOWN_PAGE%%END%%HEADER%');
        $show = $Page->show();
        $this->rollList = M('rolls')->where($map)->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('show',$show);// 赋值分页输出
        $this->display();
    }

    public function roll_add()
    {
        if(IS_POST){
            $rollObj = D('Rolls');
            $obj = $rollObj->rollVerify();
            if($obj){
                $this->error($rollObj->getError());
            }
            if(is_string($rollObj->imageUpload())){//判断文件是否上传
                $this->error($rollObj->err());
            }else{
                $path = $rollObj->messg();//文件上传保存路径
                $path = 'Uploads/'.$path['savepath'].$path['savename'];
                $map = [
                    'name' => I('imageName'),
                    'desc' => I('imageDesc'),
                    'content' => I('content'),
                    'add_time' => time(),
                    'url' => $path
                ];
                $rollAdd = M('rolls')->add($map);
                if($rollAdd){
                    $this->success('添加成功');
                }else{
                    $this->error('添加失败');
                }
            }
        }
        $this->display();
    }
    //轮番删除数据和删除图片
    public function del()
    {
        header("Content-Type:text/html;charset=utf-8");
        $getId = I('id');
        $listObj = D('Rolls');
        $rollDel =$listObj->deletList($getId);
        if($rollDel){
            $this->ajaxReturn(['code' => 200,'msg' => '删除成功']);
        }else{
            $this->ajaxReturn(['code' => 400, 'msg' => '删除失败']);
        }
    }
    //轮播批量删除
    public function checkDel($id)
    {
        $rollAllDel = D('Rolls');
        $delData = $rollAllDel->delAll($id);
        if($delData){
            $this->ajaxReturn(['code' =>200, 'msg' =>'删除成功']);
        }else{
            $this->ajaxReturn(['code' => 400, 'msg' => '删除失败']);
        }
    }
    //轮播编辑
    public function roll_edit()
    {
        $id = I('id');
        $rollObj = D('Rolls');
        if(IS_POST){
            $obj = $rollObj->rollVerify();
            if($obj){
                $this->error($rollObj->getError());
            }
            $formId = I('post.id');
            if(!empty($_FILES['imageUpload']['name'])){
                $imageEdit = $rollObj->imageUpload();
                if (is_string($imageEdit)) {
                    $this->error($rollObj->err());
                }
                $imagedel = $rollObj->imageDel($formId);//删除图片

                $path = $rollObj->messg();//文件上传保存路径
                $path = 'Uploads/'.$path['savepath'].$path['savename'];

                $data['name'] = I('imageName');
                $data['desc'] = I('imageDesc');
                $data['content'] = I('content');
                $data['status'] = I('state');
                $data['url'] = $path;
                $r=$rollObj->where("id='{$formId}'")->save($data);
                if($r){
                    $this->success('修改成功');
                }else{
                    $this->error('修改失败');
                }
            }else{
                $data['name'] = I('imageName');
                $data['desc'] = I('imageDesc');
                $data['content'] = I('content');
                $data['url'] = I('imageUpload-src');
                $data['status'] = I('state');
                $r=$rollObj->where("id='{$formId}'")->save($data);
                if($r){
                    $this->success('修改成功');
                }else{
                    $this->error('修改失败1');
                }
            }
        }
        $this->imageValue = $rollObj->where(['id' =>$id])->find();
        $this->display();
    }

    public function logo(){//logo设置
        $msg=M('logo')->field('id,logo,ico,crm_logo,web_name,web_name_en')->select();
        $this->assign('msg',$msg);
        $this->display();
    }

    public function logoAddView(){//添加logo页面
        $this->display();
    }

    public function logoAdd(){//添加logo
        //print_r($_FILES);die;
        $data['web_name']=I('post.web_name') ? I('post.web_name') : $this->error('请设置网站中文名称');
        $data['web_name_en']=I('post.web_name_en') ? I('post.web_name_en') : $this->error('请设置网站英文名称');
        empty($_FILES['logo']['error']) ? '' : $this->error('请上传logo');
        empty($_FILES['ico']['error']) ? '' : $this->error('请上传ico图标');
        empty($_FILES['crm_logo']['error']) ? '' : $this->error('请上传CRM logo');

        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('jpg', 'gif', 'png','jpeg','ico');// 设置附件上传类型
        $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
        $upload->savePath  =     'logo/'; // 设置附件上传（子）目录
        // 上传文件
        $info   =   $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功
            $data['logo']='Uploads/'.$info['logo']['savepath'].$info['logo']['savename'];
            $data['ico']='Uploads/'.$info['ico']['savepath'].$info['ico']['savename'];
            $data['crm_logo']='Uploads/'.$info['crm_logo']['savepath'].$info['crm_logo']['savename'];
            $res=M('logo')->add($data);
            if($res){
                $this->success('操作成功');
            }else{
                $this->error('操作失败');
            }
        }
    }

    public function deleteLogo(){//删除logo
        $id=I('post.id') ? I('post.id') : die(json_encode(array('status'=>0,'msg'=>'非法操作')));
        $res=M('logo')->where(['id'=>$id])->delete();
        if($res){
            $this->ajaxReturn(['status' =>1, 'msg' =>'删除成功']);
        }else{
            $this->ajaxReturn(['status' => 0, 'msg' => '删除失败']);
        }
    }

    public function software(){//交易软件、插件
        $msg=M('software')->field('id,software,plug_ins,other')->order('id desc')->select();
        $this->assign('msg',$msg);
        $this->display();
    }

    public function addSoftwareView(){//上传软件页面
        $this->display();
    }

    public function addSoftware(){//上传软件
        if(!empty($_FILES['software']['error'])){
            $this->error('请上传交易软件');
        }
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize   =     3145728 ;// 设置附件上传大小
        $upload->exts      =     array('EXE', 'exe', 'net','NET');// 设置附件上传类型
        $upload->rootPath  =     './Uploads/'; // 设置附件上传根目录
        $upload->savePath  =     'software/'.date('Y-m-d His').'/'; // 设置附件上传（子）目录
        $upload->saveName = '';
        // 上传文件
        $info = $upload->upload();
        if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        }else{// 上传成功
            $data['software']='Uploads/'.$info['software']['savepath'].$info['software']['savename'];
            $data['plug_ins']=$info['plug_ins'] ? 'Uploads/'.$info['plug_ins']['savepath'].$info['plug_ins']['savename'] : '';
            $data['other']=$info['other'] ? 'Uploads/'.$info['other']['savepath'].$info['other']['savename'] : '';
            $res=M('software')->add($data);
            if($res){
                $this->success('操作成功');
            }else{
                $this->error('操作失败');
            }
        }
    }

    public function deleteSoftware(){//删除软件
        $id=I('post.id') ? I('post.id') : die(json_encode(array('status'=>0,'msg'=>'非法操作')));
        $res=M('software')->where(['id'=>$id])->delete();
        if($res){
            $this->ajaxReturn(['status' =>1, 'msg' =>'删除成功']);
        }else{
            $this->ajaxReturn(['status' => 0, 'msg' => '删除失败']);
        }
    }

    //年涨幅设置
    public function Rose_set(){
       $data = M('rose')->order('id desc')->select();
       $this->assign('data',$data);
        $this->display();
    }
    public function Radd_view(){
        $this->display();
    }

    //添加
    public function Rose_add(){
        $data['time'] = I('time')?I('time'):$this->ajaxReturn(array('error'=>"时间必填",'status'=>0));
        $data['symbol'] = I('symbol')?I('symbol'):$this->ajaxReturn(array('error'=>"品种必填",'status'=>0));
        $data['code'] = I('code')?I('code'):$this->ajaxReturn(array('error'=>"代码必填",'status'=>0));
        $data['type'] = I('type')?I('type'):$this->ajaxReturn(array('error'=>"品种类型必填",'status'=>0));
        $data['rose'] = I('rose')?I('rose'):$this->ajaxReturn(array('error'=>"涨幅必填",'status'=>0));
        $data['status'] = I('status')?I('status'):$this->ajaxReturn(array('error'=>"状态必填",'status'=>0));
        $data['online'] = I('online')?I('online'):$this->ajaxReturn(array('error'=>"上线状态必填",'status'=>0));
        $add= M('rose')->add($data);
        if($add){
            $this->ajaxReturn(array('msg'=>"添加成功",'status'=>1));
        }else{
            $this->ajaxReturn(array('error'=>"添加失败",'status'=>0));
        }
    }
    //修改
    public function Rose_save(){
        $id = I('id')?I('id'):"没有信息";
        $data=M('rose')->where(['id'=>$id])->find();

        $this->assign('data',$data);
        $this->display();
    }
    //修改写入
    public function Rose_saveData(){
        $id=I('id')?I('id'):$this->ajaxReturn(array('error'=>"信息错误",'status'=>0));
        $data['time'] = I('time')?I('time'):$this->ajaxReturn(array('error'=>"时间必填",'status'=>0));
        $data['symbol'] = I('symbol')?I('symbol'):$this->ajaxReturn(array('error'=>"品种必填",'status'=>0));
        $data['code'] = I('code')?I('code'):$this->ajaxReturn(array('error'=>"代码必填",'status'=>0));
        $data['type'] = I('type')?I('type'):$this->ajaxReturn(array('error'=>"品种类型必填",'status'=>0));
        $data['rose'] = I('rose')?I('rose'):$this->ajaxReturn(array('error'=>"涨幅必填",'status'=>0));
        $data['status'] = I('status')?I('status'):$this->ajaxReturn(array('error'=>"状态必填",'status'=>0));
        $data['online'] = I('online')?I('online'):$this->ajaxReturn(array('error'=>"上线状态必填",'status'=>0));
        $save = M('rose')->where(['id'=>$id])->save($data);
        if($save){
            $this->ajaxReturn(array('msg'=>"修改成功",'status'=>1));
        }else{
            $this->ajaxReturn(array('error'=>"修改失败",'status'=>0));
        }
    }
    //删除
    public function Rose_delete(){
        $id= I('id')?I('id'):$this->ajaxReturn(array('error'=>"信息错误",'status'=>0));
        $delete=M('rose')->where(['id'=>$id])->delete();
        if($delete){
            $this->ajaxReturn(array('msg'=>"删除成功",'status'=>1));
        }else{
            $this->ajaxReturn(array('error'=>"删除失败",'status'=>0));
        }
    }

    public function aeronautical(){//航空公司数据
        $admin = session('admin');
        if(empty($admin)){echo "身份信息过期请重新登录";exit;}
        $model = M('aeronautical');
        $count = $model->count();
        $Page = new \Think\Page($count,20);
        $show = $Page->show();
        $list = $model->field('id,name,code,address,status')->order('id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
        $this->assign('list',$list);
        $this->assign('page',$show);
        $this->display();
    }

    public function addAeronauticalView(){//添加航空公司数据页面
        $this->display();
    }

    public function addAeronautical(){//添加航空公司数据
        $data['name']=I('post.name') ? I('post.name') : die(json_encode(array('status'=>0,'msg'=>'请设置航空名称')));
        $data['code']=I('post.code') ? I('post.code') : die(json_encode(array('status'=>0,'msg'=>'请设置航空代码')));
        $data['address']=I('post.address') ? I('post.address') : die(json_encode(array('status'=>0,'msg'=>'请设置航空地区')));
        $data['status']=I('post.status') ? I('post.status') : die(json_encode(array('status'=>0,'msg'=>'请设置状态')));
        $res=M('aeronautical')->add($data);
        if($res){
            $this->ajaxReturn(array('status'=>1,'msg'=>'操作成功'));
        }else{
            $this->ajaxReturn(array('status'=>0,'msg'=>'操作失败'));
        }
    }

    public function updateAeronauticalView(){//修改航空公司数据页面
        $id=I('id') ? I('id') : die('非法操作，<a href="javascript:history.back(-1)">点击返回</a>');
        $msg=M('aeronautical')->where(['id'=>$id])->find();
        $this->assign('msg',$msg);
        $this->display();
    }

    public function updateAeronautical(){//修改航空公司数据
        $id=I('post.id') ? I('post.id') : die(json_encode(array('status'=>0,'msg'=>'非法操作')));
        $data['name']=I('post.name') ? I('post.name') : die(json_encode(array('status'=>0,'msg'=>'请设置航空名称')));
        $data['code']=I('post.code') ? I('post.code') : die(json_encode(array('status'=>0,'msg'=>'请设置航空代码')));
        $data['address']=I('post.address') ? I('post.address') : die(json_encode(array('status'=>0,'msg'=>'请设置航空地区')));
        $data['status']=I('post.status') ? I('post.status') : die(json_encode(array('status'=>0,'msg'=>'请设置状态')));
        $res=M('aeronautical')->where(['id'=>$id])->save($data);
        if($res){
            $this->ajaxReturn(array('status'=>1,'msg'=>'操作成功'));
        }else{
            $this->ajaxReturn(array('status'=>0,'msg'=>'操作失败'));
        }
    }

    public function deleteAeronautical(){//删除航空公司数据
        $id=I('post.id') ? I('post.id') : die(json_encode(array('status'=>0,'msg'=>'非法操作')));
        $res=M('aeronautical')->where(['id'=>$id])->delete();
        if($res){
            $this->ajaxReturn(array('status'=>1,'msg'=>'操作成功'));
        }else{
            $this->ajaxReturn(array('status'=>0,'msg'=>'操作失败'));
        }
    }

}